package rsj.service.report;

import com.alibaba.fastjson.JSON;
import com.rlyy.aibase.utils.base.TableNode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import rsj.api.report.entity.AccountReport;
import rsj.api.report.entity.AccountReportDetail;
import rsj.api.report.entity.ReportParam;
import rsj.sql.account.AccountReportDao;

import java.util.List;

/**
 * 账号报表
 *
 * @author yuanqinglong
 * @since 2021/7/21 16:53
 */
@Service
public class AccountReportServiceImpl implements IReportService<AccountReport, AccountReportDetail, ReportParam> {


    @Autowired
    private AccountReportDao accountReportDao;



    /**
     * 报表列表
     *
     * @param param 参数
     * @return {@link List<AccountReport>}
     */
    @Override
    public List<AccountReport> reportList(ReportParam param) {
        TableNode reportList = accountReportDao.accountReportList(param);
        List<AccountReport> accountReports = JSON.parseArray(reportList.toJson(), AccountReport.class);
        accountReports.forEach(AccountReport::calculateRate);
        return accountReports;
    }

    /**
     * 出口数量
     *
     * @param param 参数
     * @return int
     */
    @Override
    public int reportCount(ReportParam param) {
        return accountReportDao.accountReportCount(param).valueInt();
    }

    /**
     * 详细的列表
     *
     * @param reportParam 报告参数
     * @return {@link List<AccountReportDetail>}
     */
    @Override
    public List<AccountReportDetail> detailList(ReportParam reportParam) {
        TableNode detailList = accountReportDao.accountReportDetailList(reportParam);
        List<AccountReportDetail> accountReports = JSON.parseArray(detailList.toJson(), AccountReportDetail.class);
        accountReports.forEach(AccountReportDetail::calculateRate);
        return accountReports;
    }

    /**
     * 详细的计算
     *
     * @param reportParam 报告参数
     * @return int
     */
    @Override
    public int detailCount(ReportParam reportParam) {
        return accountReportDao.accountReportDetailCount(reportParam).valueInt();
    }




}
